#include "m_hmupdate.h"
#include "ui_m_hmupdate.h"

#include <QMessageBox>
#include <QSqlQuery>

extern QString global_id2;
m_HMupdate::m_HMupdate(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::m_HMupdate)
{
    ui->setupUi(this);
    ui->sidEdit->setText(global_id2);
    _query();
}

m_HMupdate::~m_HMupdate()
{
    delete ui;
}

void m_HMupdate::_query(){
    QString str=QString("select * from housemaster left outer join hb  on(housemaster.hid=hb.hou_hid) where hid='%1'").arg(global_id2);
    QSqlQuery query;
    query.exec(str);
    if(query.next()){
        ui->snameEdit->setText(query.value(1).toString());
        ui->ssexEdit->setText(query.value(2).toString());
        ui->sphoneEdit->setText(query.value(3).toString());
        ui->haddressEdit->setText(query.value(4).toString());
        //ui->hbuildEdit->setText(query.value(5).toString());
        //ui->htimeEdit->setText(query.value(6).toString());
       // ui->spwdEdit->setText(query.value(7).toString());
        ui->spwdEdit->setText(query.value(5).toString());
    }

}
void m_HMupdate::on_confirmBtn_accepted()
{
    QSqlQuery query;
    QString sid=ui->sidEdit->text();
    QString sname=ui->snameEdit->text();
    QString ssex=ui->ssexEdit->text();
    QString sphone=ui->sphoneEdit->text();
    QString address=ui->haddressEdit->text();
    QString build=ui->hbuildEdit->text();
    QString times=ui->htimeEdit->text();
    //QString sbuildid=ui->sbuildEdit->text();
    QString spwd=ui->spwdEdit->text();

    QString str=QString("call a_housemaster('%1','%2','%3')").arg(build).arg(sid).arg(times);
    qDebug()<<str;

    if(query.exec(str)){
        QMessageBox::information(NULL,"tips","添加成功");
        this->close();
    }
    else QMessageBox::warning(NULL,"Error","添加失败，请检查是否有内容写错");
}

